import { computed } from 'vue'
import store from '@/store/index.js'
import Contact from '@/api/client/contact.js'
const briefInfo = computed(() => store.state.client.briefInfo)
export function useRules(id, contactId) {
  const rules = {
    contactName: [
      {
        required: true,
        whitespace: true,
        message: 'Please input Name',
        trigger: 'blur'
      }
    ],
    email: [
      {
        required: true,
        whitespace: true,
        message: 'Please input E-mail',
        trigger: 'blur'
      },
      {
        type: 'email',
        message: 'Incorrect email address format',
        trigger: 'blur'
      },
      {
        validator: (rule, value) => {
          const regex = /@(ecinnovations)\./g
          return regex.test(value) ? Promise.reject(new Error()) : Promise.resolve()
        },
        message: 'Incorrect email suffix',
        trigger: 'blur'
      }
      /* 邮箱唯一性验证
      {
        asyncValidator: (rule, value) => Contact.isUniqueEmailInThisClient(rule, value, id, contactId),
        message: 'The other contacts have the same email address.',
        trigger: 'blur'
      }
       */
    ],
    contactType: [
      {
        type: 'number',
        required: true,
        message: 'Please select the type',
        trigger: 'blur'
      }
    ]
  }
  if (briefInfo.value.isExisting) {
    rules.gender = [
      {
        required: true,
        type: 'number',
        message: 'Please Select Gender',
        trigger: 'blur'
      }
    ]
    rules.title = [
      {
        required: true,
        whitespace: true,
        message: 'Please Input Title',
        trigger: 'blur'
      }
    ]
    rules.department = [
      {
        required: true,
        whitespace: true,
        message: 'Please Input Department',
        trigger: 'blur'
      }
    ]
    rules.rFinancialMailType = [
      {
        required: true,
        type: 'number',
        min: 1,
        message: 'Please Select',
        trigger: 'blur'
      }
    ]
  }
  return rules
}
